<?php

namespace app\controllers;

use app\librarys\PayProController;
use app\models\ApiLog;
use app\models\SysExceptionLog;
use app\models\SysOperateLog;
use yii\data\Pagination;

class LogRecordController extends PayProController
{
    public $enableCsrfValidation = false;

    //region 操作日志
    public function actionSysOperateLog()
    {
        $request = \Yii::$app->request;
        $controllerId = $request->get('controllerId');
        $actionId = $request->get('actionId');
        $durationTime = $request->get('durationTime');
        $startTime = $request->get('startTime');
        $endTime = $request->get('endTime');

        $pagination = new Pagination([
            'totalCount' => SysOperateLog::getCount($controllerId, $actionId, $durationTime, $startTime, $endTime),
        ]);

        $records = SysOperateLog::getList($pagination->page, $pagination->pageSize, $controllerId, $actionId, $durationTime, $startTime, $endTime);

        return $this->render('sys-operate-log',
            [
                'records' => $records,
                'pagination' => $pagination,
                'controllerId' => $controllerId,
                'actionId' => $actionId,
                'durationTime' => $durationTime,
                'startTime' => $startTime,
                'endTime' => $endTime
            ]);
    }

    public function actionSysOperateLogPartial()
    {
        $logId = \Yii::$app->request->post('log_id');
        $log = SysOperateLog::getById($logId);
        return $this->renderPartial('sys-operate-log-partial', ['log' => $log]);
    }
    //endregion

    //region 错误日志
    public function actionSysExceptionLog()
    {
        $request = \Yii::$app->request;
        $controllerId = $request->get('controllerId');
        $actionId = $request->get('actionId');
        $startTime = $request->get('startTime');
        $endTime = $request->get('endTime');

        $pagination = new Pagination([
            'totalCount' => SysExceptionLog::getCount($controllerId, $actionId, $startTime, $endTime),
        ]);

        $records = SysExceptionLog::getList($pagination->page, $pagination->pageSize, $controllerId, $actionId, $startTime, $endTime);

        return $this->render('sys-exception-log',
            [
                'records' => $records,
                'pagination' => $pagination,
                'controllerId' => $controllerId,
                'actionId' => $actionId,
                'startTime' => $startTime,
                'endTime' => $endTime
            ]);
    }

    public function actionSysExceptionLogPartial()
    {
        $logId = \Yii::$app->request->post('log_id');
        $log = SysExceptionLog::getById($logId);
        return $this->renderPartial('sys-exception-log-partial', ['log' => $log]);
    }
    //endregion
}